package com.android.presenter.info;

import android.content.Context;

import com.android.model.net.HttpObserver;
import com.android.presenter.base.BasePresenter;
import com.android.model.info.LocalSp;
import com.android.model.info.UserModel;
import com.android.model.entity.res.AccountInfoResult;
import com.android.presenter.iview.IAccountInfoView;
import com.android.util.log.LogUtil;

/**
 * author:  TenFace
 * date:    2017/9/27
 * description: 查询账户信息
 */

public class AccountInfoPresenter extends BasePresenter<IAccountInfoView> {

    private static final String TAG = AccountInfoPresenter.class.getSimpleName();
    private UserModel mUserModel;

    public AccountInfoPresenter(IAccountInfoView accountInfoView) {
        super(accountInfoView);
        mUserModel = UserModel.getInstance();
    }

    public void queryAccountInfo(final Context context, String token) {
        mUserModel.queryAccountInfo(token, new HttpObserver<AccountInfoResult>() {
            @Override
            public void onSuccess(AccountInfoResult accountInfoResult) {
                LogUtil.e(TAG, "查询成功！");
                if (mIView != null) {
                    mIView.getAccountInfoSuccess(accountInfoResult);
                    LocalSp.getInstance(context).saveAccountInfoId(accountInfoResult.getAccountId());
                }
            }

            @Override
            public void onError(int errType, String errMessage) {
                LogUtil.e(TAG, "失败码：" + errType + "》》信息：" + errMessage);
                if (mIView != null) {
                    mIView.getAccountInfoFail(errType, errMessage);
                }
            }
        }, mIView.getLifeSubject());
    }

}
